package com.sx.gongzhong.adapter;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sx.gongzhong.R;
import com.sx.gongzhong.model.LegalAdviceBean;
import com.sx.gongzhong.net.ServiceFactory;

import java.util.List;

/**
 * 法律咨询
 * Created by XZY on 2017/12/28
 */

public class LegalAdviceListAdapter extends BaseQuickAdapter<LegalAdviceBean,BaseViewHolder> {

    private Context context;

    public LegalAdviceListAdapter(Context context, @LayoutRes int layoutResId, @Nullable List<LegalAdviceBean> data) {
        super(layoutResId, data);
        this.context=context;
    }

    @Override
    protected void convert(BaseViewHolder helper, LegalAdviceBean item) {
        helper.setText(R.id.tv_Content,item.content);
        helper.setText(R.id.tv_Time,item.advisoryTime);
        helper.setText(R.id.tv_Type,"#"+item.advisoryType.name);
        TextView State = helper.getView(R.id.tv_State);//handleState ;//处理状态,待回复to_be_reply,已回复replied ,
        if (item.handleState.equals("to_be_reply")){
            State.setText("待回复");
            State.setBackgroundResource(R.drawable.shape_red_corner_50);
        }else if (item.handleState.equals("replied")){
            State.setText("已回复");
            State.setBackgroundResource(R.drawable.shape_green_corner_50);
        }
        if (item.advisoryUser != null){
            helper.setText(R.id.tv_Name,item.advisoryUser.getName());
            ImageView iv_headerUrl = helper.getView(R.id.im_Head);
            RequestOptions options = new RequestOptions().centerCrop()
                    .placeholder(R.mipmap.img_head_default)
                    .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                    .circleCrop()
                    .error(R.mipmap.img_head_default);
            Glide.with(context)
                    .load(ServiceFactory.getUrl(item.advisoryUser.getHeaderUrl()))
                    .apply(options)
                    .into(iv_headerUrl);
        }
    }


}
